package com.example.composeplayground

import android.app.Application
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.Utils
import com.example.composeplayground.exceptions.AlertException
import com.example.composeplayground.exceptions.ToastException
import com.example.composeplayground.states.AlertManager

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Utils.init(this)
        Thread.setDefaultUncaughtExceptionHandler { _, throwable ->
            run {
                when (throwable) {
                    is ToastException -> throwable.message?.let { ToastUtils.showShort(it) }
                    is AlertException -> throwable.message?.let { AlertManager.show(it) }
                    else -> throw throwable
                }
            }
        }
    }
}